package com.ruoyi.system.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.system.domain.vo.Approval.ApprovalForm.ApprovalCategoryVO;
import com.ruoyi.system.domain.vo.Approval.ApprovalForm.ApproverVO;
import com.ruoyi.system.service.IApprovalFormService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/approval/form")
public class ApprovalFormController extends BaseController {

    @Autowired
    private IApprovalFormService approvalFormService;

    @GetMapping("/approvers")
    public TableDataInfo selectApprovers()
    {
        List<ApproverVO> list = approvalFormService.selectApprovers();
        return getDataTable(list);
    }

    @GetMapping("/approvalCategories")
    public TableDataInfo selectApprovalCategoriesByDefaultApproverId(@RequestParam("defaultApproverId") Integer defaultApproverId)
        {
            List<ApprovalCategoryVO> list = approvalFormService.selectApprovalCategoriesByDefaultApproverId(defaultApproverId);
            return getDataTable(list);
        }

    @PutMapping("/changeDefaultApprover")
    public AjaxResult changeDefaultApprover(@RequestParam("id") Integer id, @RequestParam("nextId") Integer nextId)
    {
        return toAjax(approvalFormService.changeDefaultApprover(id,nextId));
    }
}
